import maya.cmds as mc
# -*- coding: UTF-8 -*-
#import sys
#sys.path.append('E:/script/RC_scripts')
class driver_win():
    def driver_win(self):
        driver_win = 'driver_win'
        if mc.window(driver_win,ex = True):
            mc.deleteUI(driver_win)
        
        mc.window(driver_win,widthHeight=(300, 200),t='driver_win v1.01',menuBar = True,rtf=True,s=True)
        
        mc.rowColumnLayout('Main',numberOfColumns=1,w=300,cal = (5,'center'),m=True)
        mc.rowColumnLayout('createSettingLY',numberOfColumns=2,w=300,cal = (5,'center'),m=True)
        mc.text('setting section',w=80,l='setting  name :')
        mc.textField('settingBasename',w=200,text='L_arm')
        mc.setParent('..')
        mc.button('crete Setting',h=30,c=lambda *args:self.createSetting())
        mc.rowColumnLayout('nameFieldLay',numberOfColumns=3,w=300,cal = (5,'center'),m=True)
        #mc.text('nodeText',l='node name')
        #mc.textField('nodename')
        #mc.button(l='load Node',c=lambda *args:self.loadSelectNode())
        
        mc.text('distanceText',l='distance name :',w=100)
        mc.textField('SDK_bridge_name')
        mc.button(l='load distance',w=100,c=lambda *args:self.loadBridgeNode())
        mc.setParent('..')
        
        mc.rowColumnLayout('SDK_Direction',numberOfColumns=2,cal = (5,'center'),m=True)
        mc.optionMenu('SDK_DirectionMenu',label='',w=200,h=30,cc=lambda *args:self.changSelectButtonEnbale())


        mc.menuItem( label='            __ Front __' )
        mc.menuItem( label='            __  up  __' )
        mc.menuItem( label='            __back__' )
        mc.menuItem( label='            __bottom __' )
        mc.menuItem( label='            __front_up__' )
        mc.menuItem( label='            __back_up__' )
        mc.menuItem( label='            __front_bottom__' )
        mc.menuItem( label='            __back_bottom__' )
        
        mc.button('changeAngle',l='set Angle',en=False,c=lambda *args:self.changAngle())
        mc.setParent('..')
        
        
        mc.rowColumnLayout('SDK_button',numberOfColumns=2,cal = (5,'center'),m=True)
        mc.button('setMinValue',w=150,h=30,c=lambda *args:self.setMaxValue())
        
        mc.button('setMaxValue',w=150,h=30,c=lambda *args:self.setMinValue())
        mc.setParent('..')
        mc.radioButtonGrp( 'mirrorAxis',numberOfRadioButtons=3,label='mirror Axis  :', labelArray3=['x', 'y', 'z'],columnWidth4=[120,50,50,50],select=1,w=300,enableBackground=True )
        mc.rowColumnLayout('mirrorLY',numberOfColumns=2,cal = (5,'center'),m=True)
        mc.text('prefixname',l='search for :',w=130)
        mc.textField('prefixname',w=150,text='L_')
        mc.text('suffixname',l='replace with :',w=130)
        mc.textField('suffixname',w=150,text='R_'    )
        mc.setParent('..')
        mc.button(l='mirrior driver setting ',c=lambda *args:self.mirrorSetting())

        mc.showWindow()

        
        
    def continer_BG(self,name='',addNodeMember=[],inputAttr_grp=[('inputA','connectInputAttr')],outAttr=['']):
    
        mc.createNode('dagContainer',n=name)
        mc.container( name, e=True, addNode = addNodeMember,includeNetwork=True,includeHierarchyBelow=True)
        mc.setAttr(str(name)+'.blackBox',1,lock=True)
        mc.setAttr(str(name) + '.creator','author: li zhi ',type='string',lock=True)
        
        mc.addAttr(name,ln='input_Attributes')
        mc.setAttr(str(name)+'.input_Attributes',cb=True,lock=True)
        
        #  add  inputAttributes 
        for at in inputAttr_grp:
            inputAttr= at[0]
            outputAttr= at[1]
            
            mc.addAttr(name,ln=inputAttr)
            mc.setAttr(str(name) + '.'+ str(inputAttr),k=True)
            mc.connectAttr(str(name)+'.'+str(inputAttr), outputAttr )
            
            
        mc.addAttr(name,ln='output_Attributes')
        mc.setAttr(str(name)+'.output_Attributes',cb=True,lock=True)
        for outAt in outAttr :
            mc.addAttr(name,ln=outAt)
            mc.setAttr(str(name) + '.'+ str(outAt),k=True)
            
            
    def changAngle(self):
        bridge=mc.textField('SDK_bridge_name',q=True,text=True)

        selValue=mc.optionMenu('SDK_DirectionMenu',q=True,sl=True)
        attrSDK=['.angle_frontUp','.angle_backUp','.angle_frontBottom','.angle_backBottom']
        currentAttr='.angle_base'
        currentValue=mc.getAttr(str(bridge)+currentAttr)

        mc.setAttr(str(bridge)+attrSDK[selValue-5],currentValue)
    def changSelectButtonEnbale(self):
        selValue=mc.optionMenu('SDK_DirectionMenu',q=True,sl=True)
        if selValue<4:
            mc.button('changeAngle',e=True,en=False)
        else:
            mc.button('changeAngle',e=True,en=True)
    def createSetting(self):
        settignname=mc.textField('settingBasename',q=True,text=True)
        self.createSettingLoc(settignname)
    def loadBridgeNode(self):
        slObj=mc.ls(sl=True)[0]
        mc.textField('SDK_bridge_name',e=True,text=slObj)
    def setMinValue(self):
        #slobj=mc.ls(sl=True)
        bridge=mc.textField('SDK_bridge_name',q=True,text=True)

        selValue=mc.optionMenu('SDK_DirectionMenu',q=True,sl=True)
        attrSDK=['.min_front_input','.min_up_input','.min_back_input','.min_bottom_input','.min_frontUp_input','.min_backUp_input','.min_frontBottom_input','.min_backBottom_input']
        currentAttr=['.distance_front_currentlen','.distance_up_currentlen','.distance_back_currentlen','.distance_bottom_currentlen','.distance_frontUp_currentlen','.distance_backUp_currentlen','.distance_frontBottom_currentlen','.distance_backBottom_currentlen']
        
        globalScale=mc.getAttr(str(bridge)+'.global_scale')
        currentValue=mc.getAttr(str(bridge)+currentAttr[selValue-1])
        sdkValue=currentValue/globalScale
        
        mc.setAttr(str(bridge)+attrSDK[selValue-1],sdkValue)
        
    def setMaxValue(self):
        #slobj=mc.ls(sl=True)
        bridge=mc.textField('SDK_bridge_name',q=True,text=True)

        selValue=mc.optionMenu('SDK_DirectionMenu',q=True,sl=True)
        attrSDK=['.max_front_input','.max_up_input','.max_back_input','.max_bottom_input','.max_frontUp_input','.max_backUp_input','.max_frontBottom_input','.max_backBottom_input']
        currentAttr=['.distance_front_currentlen','.distance_up_currentlen','.distance_back_currentlen','.distance_bottom_currentlen','.distance_frontUp_currentlen','.distance_backUp_currentlen','.distance_frontBottom_currentlen','.distance_backBottom_currentlen']
        
        globalScale=mc.getAttr(str(bridge)+'.global_scale')
        currentValue=mc.getAttr(str(bridge)+currentAttr[selValue-1])
        sdkValue=currentValue/globalScale
        
        mc.setAttr(str(bridge)+attrSDK[selValue-1],sdkValue)
    def setMinV(self):
        #node=mc.textField('nodename',q=True,text=True)
        #distance=mc.textField('distancename',q=True,text=True)
        #shapenode=mc.listRelatives(distance,s=True)[0]
        #distanceValue=mc.getAttr(str(shapenode)+'.distance')
        #mc.setAttr(str(node)+'.inputMax',distanceValue)
        bridge=mc.textField('SDK_bridge_name',q=True,text=True)
        globalScale=mc.getAttr(str(bridge)+'.global_scale')
        globalScale=mc.getAttr(str(bridge)+'.global_scale')
        
    def setMaxV(self):
        node=mc.textField('nodename',q=True,text=True)
        distance=mc.textField('distancename',q=True,text=True)
        shapenode=mc.listRelatives(distance,s=True)[0]
        distanceValue=mc.getAttr(str(shapenode)+'.distance')
        mc.setAttr(str(node)+'.inputMin',distanceValue)
    def mirrorSetting(self):
        bridge=mc.textField('SDK_bridge_name',q=True,text=True)
        grp=bridge.replace('bridge','grp')
        org = mc.textField('prefixname',q=True,text=True)
        replace = mc.textField('suffixname',q=True,text=True)
        mirrorBridge=bridge.replace(org,replace)
        
        mirrorGrp=grp.replace(org,replace)
        splits=mirrorGrp.split('_')
        pre=splits[0:-1]
        
        for i in range(len(pre)):
            if i==0:
                mirrorsetting=pre[i]
            else:
                mirrorsetting=mirrorsetting+'_'+pre[i]
        self.createSettingLoc(mirrorsetting)
        orgsetting=mirrorsetting.replace(replace,org)
        
        
        locPos='_pos_grp'
        locpon=['_frontLoc','_upLoc','_backLoc','_bottomLoc','_frontUpLoc','_backUpLoc','_frontBottomLoc','_backBottomLoc','_state_Angloc']
        attr=['angle_frontUp','angle_backUp','angle_frontBottom','angle_backBottom']

        
        
        orggrptranslate=mc.xform(grp,q=True,t=True,ws=True)
        orggrprotate=mc.xform(grp,q=True,ro=True,ws=True)
        
        mirrorAxis=mc.radioButtonGrp( 'mirrorAxis',q=True,select=True)
        if mirrorAxis==1:
            mc.xform(mirrorGrp,ws=True,t=(-1*orggrptranslate[0],orggrptranslate[1],orggrptranslate[2]))
            mc.xform(mirrorGrp,ws=True,ro=(orggrprotate[0],-1*orggrprotate[1],-1*orggrprotate[2]))
            
            org_postranslateX=mc.getAttr(orgsetting+locPos+'.translateX')
            mc.setAttr(mirrorsetting+locPos+'.translateX',-1*org_postranslateX)
            for lp in locpon:
                org_translateX=mc.getAttr(orgsetting+lp+'.translateX')
                mc.setAttr(mirrorsetting+lp+'.translateX',-1*org_translateX)
                
            
        if mirrorAxis==2:
            mc.xform(mirrorGrp,ws=True,t=(orggrptranslate[0],-1*orggrptranslate[1],orggrptranslate[2]))
            mc.xform(mirrorGrp,ws=True,ro=(-1*orggrprotate[0],orggrprotate[1],-1*orggrprotate[2]))
            
            org_postranslateY=mc.getAttr(orgsetting+locPos+'.translateY')
            mc.setAttr(mirrorsetting+locPos+'.translateY',-1*org_postranslateY)
            for lp in locpon:
                org_translateY=mc.getAttr(orgsetting+lp+'.translateY')
                mc.setAttr(mirrorsetting+lp+'.translateY',-1*org_translateY)
            
        if mirrorAxis==3:
            mc.xform(mirrorGrp,ws=True,t=(orggrptranslate[0],orggrptranslate[1],-1*orggrptranslate[2]))
            mc.xform(mirrorGrp,ws=True,ro=(-1*orggrprotate[0],-1*orggrprotate[1],orggrprotate[2]))
            
            org_postranslateZ=mc.getAttr(orgsetting+locPos+'.translateZ')
            mc.setAttr(mirrorsetting+locPos+'.translateZ',-1*org_postranslateZ)
            for lp in locpon:
                org_translateZ=mc.getAttr(orgsetting+lp+'.translateZ')
                mc.setAttr(mirrorsetting+lp+'.translateZ',-1*org_translateZ)
        
 
        for at in attr:
            org_at=mc.getAttr(bridge+'.'+at)
            mc.setAttr(mirrorBridge+'.'+at,org_at)
        
        
        
        
    def createSettingLoc(self,locPart):
        locAll=['frontLoc','upLoc','backLoc','bottomLoc','pointLoc','posLoc','stateLoc']
        angleLoc=['base_Angloc','follow_Angloc','state_Angloc']
        obliqueLocAll=['frontUpLoc','backUpLoc','frontBottomLoc','backBottomLoc']
        locname=[str(locPart)+'_'+locAll[0],str(locPart)+'_'+locAll[1],str(locPart)+'_'+locAll[2],str(locPart)+'_'+locAll[3],str(locPart)+'_'+locAll[4],str(locPart)+'_'+locAll[5],str(locPart)+'_'+locAll[6]]
        obliqueLoc=[str(locPart)+'_'+obliqueLocAll[0],str(locPart)+'_'+obliqueLocAll[1],str(locPart)+'_'+obliqueLocAll[2],str(locPart)+'_'+obliqueLocAll[3]]
        anglocAll=[str(locPart)+'_'+angleLoc[0],str(locPart)+'_'+angleLoc[1],str(locPart)+'_'+angleLoc[2]]
        
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[0])
        mc.move(-5,0,5,locname[0])
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[1])
        mc.move(-5,5,0,locname[1])
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[2])
        mc.move(-5,0,-5,locname[2])
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[3])
        mc.move(-5,-5,0,locname[3])
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[4])
        mc.move(0,0,0,locname[4])
        mc.setAttr(str(locname[4])+'.visibility',0)
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[5])
        mc.move(5,0,0,locname[5])
        
        mc.select(cl=True)
        mc.spaceLocator(n=locname[6])
        mc.move(5,0,0,locname[6])
        mc.setAttr(str(locname[6])+'.visibility',0)
        #-------------------------------------------
        mc.select(cl=True)
        mc.spaceLocator(n=obliqueLoc[0])
        mc.move(-5,5,5,obliqueLoc[0])
        
        mc.select(cl=True)
        mc.spaceLocator(n=obliqueLoc[1])
        mc.move(-5,5,-5,obliqueLoc[1])
        
        mc.select(cl=True)
        mc.spaceLocator(n=obliqueLoc[2])
        mc.move(-5,-5,5,obliqueLoc[2])
        
        mc.select(cl=True)
        mc.spaceLocator(n=obliqueLoc[3])
        mc.move(-5,-5,-5,obliqueLoc[3])
        
        
        
        mc.select(cl=True)
        mc.spaceLocator(n=anglocAll[0])
        mc.move(0,0,0,anglocAll[0])
        mc.setAttr(str(anglocAll[0])+'.visibility',0)
        
        mc.select(cl=True)
        mc.spaceLocator(n=anglocAll[1])
        mc.move(5,0,0,anglocAll[1])
        mc.setAttr(str(anglocAll[1])+'.visibility',0)
        
        mc.select(cl=True)
        mc.spaceLocator(n=anglocAll[2])
        mc.move(5,0,0,anglocAll[2])
        mc.setAttr(str(anglocAll[2])+'.visibility',0)
        
        
        
        ###################################################
        mc.transformLimits(locname[4],tx=(0,0),etx=(True,True))
        mc.pointConstraint(locname[5],locname[4])
        
        mc.pointConstraint(locname[5],anglocAll[1])
        #######################
        mc.group(n=str(locPart)+'_grp',em=True)
        mc.parent(locname[0],locname[1],locname[2],locname[3],locname[4],locname[5],locname[6],obliqueLoc[0],obliqueLoc[1],obliqueLoc[2],obliqueLoc[3],anglocAll[0],anglocAll[1],anglocAll[2],str(locPart)+'_grp')
        #######################
        
        
        
        
        
        #######################                                                       #//add  attribute  on bridge group
        mc.group(n=str(locPart)+'_bridge',em=True)
        mc.parent(str(locPart)+'_bridge',str(locPart)+'_grp')
        #mc.addAttr(str(locPart)+'_bridge',ln='local_scale',dv=1)                      #//
        #mc.setAttr(str(locPart)+'_bridge.local_scale',keyable=True)                   #//
        #mc.addAttr(str(locPart)+'_bridge',ln='global_scale',dv=1)                     #//
        #mc.setAttr(str(locPart)+'_bridge.global_scale',keyable=True)                  #//
        
        
        #
        #----------------------------------------------------------------
        
        mc.addAttr(str(locPart)+'_bridge',at='enum',ln='__',en='current_length')
        mc.setAttr(str(locPart)+'_bridge.__',keyable=True,l=True)
        
  
        #
        #--------------------------------------------------------------
        
   
        #--------------------------------------------------------------
        #

        #--------------------------------------------------------------


        #--------------------------------------------

        #
        #-------------------------------------------------

        #-----------------------------------------------------
        #

        #
        #--------------------------------------------------------
        

        
        ##-------------------------------------------------------
        ##
        
        mc.addAttr(str(locPart)+'_bridge',ln='driver_vulue')                  
        mc.setAttr(str(locPart)+'_bridge.driver_vulue',keyable=True) 
        #
        #---------------------------------------------------------------

        mc.addAttr(str(locPart)+'_bridge',at='enum',ln='_______',en='angle_base')      #//
        mc.setAttr(str(locPart)+'_bridge._______',keyable=True,l=True)  
        mc.addAttr(str(locPart)+'_bridge',ln='angle_base')
        mc.setAttr(str(locPart)+'_bridge.angle_base',keyable=True)      
        
  
        
        #---------------------------------------------------------------
        #
        mc.addAttr(str(locPart)+'_bridge',ln='angle_frontUp',dv=45,min=1,max=89)
        mc.setAttr(str(locPart)+'_bridge.angle_frontUp',keyable=True)      
        mc.addAttr(str(locPart)+'_bridge',ln='angle_backUp',dv=135,min=91,max=179)
        mc.setAttr(str(locPart)+'_bridge.angle_backUp',keyable=True)      
        mc.addAttr(str(locPart)+'_bridge',ln='angle_frontBottom',dv=45,min=1,max=89)
        mc.setAttr(str(locPart)+'_bridge.angle_frontBottom',keyable=True)      
        mc.addAttr(str(locPart)+'_bridge',ln='angle_backBottom',dv=135,min=91,max=179)
        mc.setAttr(str(locPart)+'_bridge.angle_backBottom',keyable=True)      
        #
        #------------------------------------------------------------------

        
        #
        #-----------------------------------------------------------------------
        
                           #//
        mc.addAttr(str(locPart)+'_bridge',at='enum',ln='_________',en='Interval_sevalue') 
        mc.setAttr(str(locPart)+'_bridge._________',keyable=True,l=True)         
        mc.addAttr(str(locPart)+'_bridge',ln='Interval_sevalue')
        mc.setAttr(str(locPart)+'_bridge.Interval_sevalue',keyable=True)
        
        mc.addAttr(str(locPart)+'_bridge',at='enum',ln='__________',en='SDK_driver') 
        mc.setAttr(str(locPart)+'_bridge.__________',keyable=True,l=True)         
        mc.addAttr(str(locPart)+'_bridge',ln='front_driver')
        mc.setAttr(str(locPart)+'_bridge.front_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='up_driver')
        mc.setAttr(str(locPart)+'_bridge.up_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='back_driver')
        mc.setAttr(str(locPart)+'_bridge.back_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='bottom_driver')
        mc.setAttr(str(locPart)+'_bridge.bottom_driver',keyable=True)
        
        #------------------------------------------------------------
        #
        mc.addAttr(str(locPart)+'_bridge',ln='frontUp_driver')
        mc.setAttr(str(locPart)+'_bridge.frontUp_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='backUp_driver')
        mc.setAttr(str(locPart)+'_bridge.backUp_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='frontBottom_driver')
        mc.setAttr(str(locPart)+'_bridge.frontBottom_driver',keyable=True)
        mc.addAttr(str(locPart)+'_bridge',ln='backBottom_driver')
        mc.setAttr(str(locPart)+'_bridge.backBottom_driver',keyable=True)
        
        #
        #-------------------------------------------------------------
        angleNode=str(locPart)+'_angle_AB_Bt'
        anglePMANode01=str(locPart)+'_anglePMA01'
        anglePMANode02=str(locPart)+'_anglePMA02'
        
        mc.createNode('angleBetween',n=angleNode)
        mc.createNode('plusMinusAverage',n=anglePMANode01)
        
        mc.setAttr(str(anglePMANode01)+'.operation',2)
        mc.connectAttr(str(anglocAll[1])+'.translateX',str(anglePMANode01)+'.input3D[0].input3Dx')
        mc.connectAttr(str(anglocAll[1])+'.translateY',str(anglePMANode01)+'.input3D[0].input3Dy')
        mc.connectAttr(str(anglocAll[1])+'.translateZ',str(anglePMANode01)+'.input3D[0].input3Dz')
        
        mc.connectAttr(str(anglocAll[0])+'.translateX',str(anglePMANode01)+'.input3D[1].input3Dx')
        mc.connectAttr(str(anglocAll[0])+'.translateY',str(anglePMANode01)+'.input3D[1].input3Dy')
        mc.connectAttr(str(anglocAll[0])+'.translateZ',str(anglePMANode01)+'.input3D[1].input3Dz')
        
        
        mc.createNode('plusMinusAverage',n=anglePMANode02)
        
        mc.setAttr(str(anglePMANode01)+'.operation',2)
        mc.connectAttr(str(anglocAll[2])+'.translateX',str(anglePMANode02)+'.input3D[0].input3Dx')
        mc.connectAttr(str(anglocAll[2])+'.translateY',str(anglePMANode02)+'.input3D[0].input3Dy')
        mc.connectAttr(str(anglocAll[2])+'.translateZ',str(anglePMANode02)+'.input3D[0].input3Dz')
        
        mc.connectAttr(str(anglocAll[0])+'.translateX',str(anglePMANode02)+'.input3D[1].input3Dx')
        mc.connectAttr(str(anglocAll[0])+'.translateY',str(anglePMANode02)+'.input3D[1].input3Dy')
        mc.connectAttr(str(anglocAll[0])+'.translateZ',str(anglePMANode02)+'.input3D[1].input3Dz')
        
        mc.connectAttr(str(anglePMANode02)+'.output3Dx',str(angleNode)+'.vector1X')
        mc.connectAttr(str(anglePMANode02)+'.output3Dy',str(angleNode)+'.vector1Y')
        mc.connectAttr(str(anglePMANode02)+'.output3Dz',str(angleNode)+'.vector1Z')
        
        mc.connectAttr(str(anglePMANode01)+'.output3Dx',str(angleNode)+'.vector2X')
        mc.connectAttr(str(anglePMANode01)+'.output3Dy',str(angleNode)+'.vector2Y')
        mc.connectAttr(str(anglePMANode01)+'.output3Dz',str(angleNode)+'.vector2Z')
        
        angleValueMD=str(locPart)+'_angValueMD'
        mc.createNode('multiplyDivide',n=angleValueMD)
        
        mc.connectAttr(str(angleNode)+'.angle',str(angleValueMD)+'.input1X')
        mc.setAttr(str(angleValueMD)+'.input2X',180)
        mc.setAttr(str(angleValueMD)+'.operation',2)
        
        mc.connectAttr(str(angleValueMD)+'.outputX',str(locPart)+'_bridge.driver_vulue')
        
        ########
        mc.select(cl=True)
        mc.spaceLocator(n=str(locPart)+'_basefrontangle_loc')
        mc.move(0,0,5,str(locPart)+'_basefrontangle_loc')
        mc.setAttr(str(locPart)+'_basefrontangle_loc.visibility',0)
        
        mc.select(cl=True)
        mc.spaceLocator(n=str(locPart)+'_baseangle_loc')
        mc.move(0,0,0,str(locPart)+'_baseangle_loc')
        mc.setAttr(str(locPart)+'_baseangle_loc.visibility',0)
        
        mc.parent(str(locPart)+'_baseangle_loc',str(locPart)+'_basefrontangle_loc',str(locPart)+'_grp')
        mc.createNode('angleBetween',n=str(locPart)+'_angleBt')
        
        angleLoc=[str(locPart)+'_basefrontangle_loc',locname[4],str(locPart)+'_baseangle_loc']
        pmanode=[str(locPart)+'_angle01_pma',str(locPart)+'_angle02_pma']
        mc.createNode('plusMinusAverage',n=pmanode[0])
        mc.setAttr(str(pmanode[0])+'.operation',2)
        mc.createNode('plusMinusAverage',n=pmanode[1])
        mc.setAttr(str(pmanode[1])+'.operation',2)
        
        for al in range(2):
            shape01=mc.listRelatives(angleLoc[al],s=True)[0]
            shape02=mc.listRelatives(angleLoc[2],s=True)[0]
            mc.connectAttr(str(shape01)+'.worldPosition[0]',str(pmanode[al])+'.input3D[0]')
            mc.connectAttr(str(shape02)+'.worldPosition[0]',str(pmanode[al])+'.input3D[1]')
        mc.connectAttr(str(pmanode[0])+'.output3D',str(locPart)+'_angleBt.vector1')
        mc.connectAttr(str(pmanode[1])+'.output3D',str(locPart)+'_angleBt.vector2')
        mc.connectAttr(str(locPart)+'_angleBt.axisAngle.angle',str(locPart)+'_bridge.angle_base')

        ################################
       
            
        #
        #------------------------------------------------------------------
        
        ##########################################################
        ##########################################################
        ##                  interval section 
        
        self.IntervalSection(locname[4],str(locPart)+'_bridge')
        #########################################################
        mc.group(n=str(locPart)+'_pos_grp',em=True)
        mc.parentConstraint(locname[5],str(locPart)+'_pos_grp',mo=False,n='templeConstraint')
        mc.delete('templeConstraint')
        mc.parent(locname[5],locname[6],str(locPart)+'_pos_grp')
        mc.parent(str(locPart)+'_pos_grp',str(locPart)+'_grp')
        mc.pointConstraint(locname[5],locname[6])
        mc.transformLimits(locname[6],tx=(0,0),etx=(True,True))
        
        
        #################
        continername = str(locPart) +'_continer'
        addMember = str(locPart)+'_grp'
        
        inputAttributes = [('angle_backBottom',str(str(locPart)+'_bridge')+'.angle_backBottom'),('angle_frontUp',str(str(locPart)+'_bridge')+'.angle_frontUp'),('angle_backUp',str(str(locPart)+'_bridge')+'.angle_backUp'),('angle_frontBottom',str(str(locPart)+'_bridge')+'.angle_frontBottom')]
        outputAttibute=['front_driver','up_driver','back_driver','bottom_driver','frontUp_driver','backUp_driver','frontBottom_driver','backBottom_driver']
        #self.continer_BG(name= continername ,addNodeMember= [addMember],inputAttr_grp = inputAttributes,outAttr=outputAttibute)
            
        
        
    def createDistance(self,starPos,endPos,nameNode):
        startShape=mc.listRelatives(starPos,s=True)[0]
        endShape=mc.listRelatives(endPos,s=True)[0]
        mc.createNode('distanceBetween',n=nameNode)
        mc.connectAttr(str(startShape)+'.worldPosition',str(nameNode)+'.point1')
        mc.connectAttr(str(endShape)+'.worldPosition',str(nameNode)+'.point2')
        
    def IntervalSection(self,referenceObj,attrObj):
        
        ################################
        ####  + + : 9    1 interval
        ####  + - : 5    2 interval
        ####  - - : 7    3 interval
        ####  - + : 3    4 interval
        
        ####  +Y 0 : 9.5    
        ####  -Y 0 : 7.5 
        ####  +Z 0 : 6 
        ####  -Z 0 : 10 
        
        sections=referenceObj.split('_')
        pre=sections[0:-1]
        objpre=''
        prenum=0
        for i in pre:
            if prenum==0:

                objpre=objpre+i
            else:
                objpre=objpre+'_'+i
            prenum=prenum+1
        selectY=objpre+'_Y_selecton_conditon'
        selectZ=objpre+'_Z_selecton_conditon'
        selectYliner=objpre+'_Yliner_selecton_conditon'
        selectZliner=objpre+'_Zliner_selecton_conditon'
        multiPMA=objpre+'_multi_pma'
        
        mc.createNode('condition',n=objpre+'_Y_selecton_conditon')
        mc.createNode('condition',n=objpre+'_Yliner_selecton_conditon')
        mc.createNode('condition',n=objpre+'_Z_selecton_conditon')
        mc.createNode('condition',n=objpre+'_Zliner_selecton_conditon')
        
        mc.connectAttr(str(referenceObj)+'.translateY',str(selectY)+'.firstTerm')
        mc.setAttr(str(selectY)+'.secondTerm',0)
        mc.setAttr(str(selectY)+'.operation',3)
        mc.setAttr(str(selectY)+'.colorIfTrueR',3)
        mc.setAttr(str(selectY)+'.colorIfFalseR',1)
        
        mc.connectAttr(str(referenceObj)+'.translateZ',str(selectZ)+'.firstTerm')
        mc.setAttr(str(selectZ)+'.secondTerm',0)
        mc.setAttr(str(selectZ)+'.operation',3)
        mc.setAttr(str(selectZ)+'.colorIfTrueR',6)
        mc.setAttr(str(selectZ)+'.colorIfFalseR',2)
        
        mc.connectAttr(str(referenceObj)+'.translateY',str(selectYliner)+'.firstTerm')
        mc.setAttr(str(selectYliner)+'.secondTerm',0)
        mc.setAttr(str(selectYliner)+'.operation',0)
        mc.setAttr(str(selectYliner)+'.colorIfTrueR',1)
        mc.setAttr(str(selectYliner)+'.colorIfFalseR',0)
        
        mc.connectAttr(str(referenceObj)+'.translateZ',str(selectZliner)+'.firstTerm')
        mc.setAttr(str(selectZliner)+'.secondTerm',0)
        mc.setAttr(str(selectZliner)+'.operation',0)
        mc.setAttr(str(selectZliner)+'.colorIfTrueR',0.5)
        mc.setAttr(str(selectZliner)+'.colorIfFalseR',0)
        
        mc.createNode('plusMinusAverage',n=multiPMA)
        
        mc.connectAttr(str(selectY)+'.outColorR',str(multiPMA)+'.input1D[0]')
        mc.connectAttr(str(selectZ)+'.outColorR',str(multiPMA)+'.input1D[1]')
        mc.connectAttr(str(selectYliner)+'.outColorR',str(multiPMA)+'.input1D[2]')
        mc.connectAttr(str(selectZliner)+'.outColorR',str(multiPMA)+'.input1D[3]')
        
        mc.connectAttr(str(multiPMA)+'.output1D',str(attrObj)+'.Interval_sevalue')
        #########################################################
        #######    output of interval 
        ### 
        outputInterval01=objpre+'_outputInterval01_conditon'
        outputInterval02=objpre+'_outputInterval02_conditon'
        outputInterval03=objpre+'_outputInterval03_conditon'
        outputInterval04=objpre+'_outputInterval04_conditon'
        outputIntervalAxis_PosY=objpre+'_outputInterval_axis_PosY_conditon'
        outputIntervalAxis_NegY=objpre+'_outputInterval_axis_negY_conditon'
        outputIntervalAxis_PosZ=objpre+'_outputInterval_axis_PosZ_conditon'
        outputIntervalAxis_NegZ=objpre+'_outputInterval_axis_negZ_conditon'
        ###
        mc.createNode('condition',n=outputInterval01)
        mc.createNode('condition',n=outputInterval02)
        mc.createNode('condition',n=outputInterval03)
        mc.createNode('condition',n=outputInterval04)
        ###
        mc.createNode('condition',n=outputIntervalAxis_PosY)
        mc.createNode('condition',n=outputIntervalAxis_NegY)
        mc.createNode('condition',n=outputIntervalAxis_PosZ)
        mc.createNode('condition',n=outputIntervalAxis_NegZ)
        ###    1 interval
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputInterval01)+'.firstTerm')
        mc.setAttr(str(outputInterval01)+'.secondTerm',9)
        mc.setAttr(str(outputInterval01)+'.operation',0)
        mc.setAttr(str(outputInterval01)+'.colorIfTrueR',1)
        mc.setAttr(str(outputInterval01)+'.colorIfFalseR',0)
        ###     2 interval
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputInterval02)+'.firstTerm')
        mc.setAttr(str(outputInterval02)+'.secondTerm',5)
        mc.setAttr(str(outputInterval02)+'.operation',0)
        mc.setAttr(str(outputInterval02)+'.colorIfTrueR',1)
        mc.setAttr(str(outputInterval02)+'.colorIfFalseR',0)
        ###   3 interval
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputInterval03)+'.firstTerm')
        mc.setAttr(str(outputInterval03)+'.secondTerm',7)
        mc.setAttr(str(outputInterval03)+'.operation',0)
        mc.setAttr(str(outputInterval03)+'.colorIfTrueR',1)
        mc.setAttr(str(outputInterval03)+'.colorIfFalseR',0)
        ###    4 interval
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputInterval04)+'.firstTerm')
        mc.setAttr(str(outputInterval04)+'.secondTerm',3)
        mc.setAttr(str(outputInterval04)+'.operation',0)
        mc.setAttr(str(outputInterval04)+'.colorIfTrueR',1)
        mc.setAttr(str(outputInterval04)+'.colorIfFalseR',0)
        ###    +Y 0
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputIntervalAxis_PosY)+'.firstTerm')
        mc.setAttr(str(outputIntervalAxis_PosY)+'.secondTerm',9.5)
        mc.setAttr(str(outputIntervalAxis_PosY)+'.operation',0)
        mc.setAttr(str(outputIntervalAxis_PosY)+'.colorIfTrueR',1)
        mc.setAttr(str(outputIntervalAxis_PosY)+'.colorIfFalseR',0)
        ###    -Y 0
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputIntervalAxis_NegY)+'.firstTerm')
        mc.setAttr(str(outputIntervalAxis_NegY)+'.secondTerm',7.5)
        mc.setAttr(str(outputIntervalAxis_NegY)+'.operation',0)
        mc.setAttr(str(outputIntervalAxis_NegY)+'.colorIfTrueR',1)
        mc.setAttr(str(outputIntervalAxis_NegY)+'.colorIfFalseR',0)
        ###    +Z 0
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputIntervalAxis_PosZ)+'.firstTerm')
        mc.setAttr(str(outputIntervalAxis_PosZ)+'.secondTerm',10)
        mc.setAttr(str(outputIntervalAxis_PosZ)+'.operation',0)
        mc.setAttr(str(outputIntervalAxis_PosZ)+'.colorIfTrueR',1)
        mc.setAttr(str(outputIntervalAxis_PosZ)+'.colorIfFalseR',0)
        ###     -Z 0
        mc.connectAttr(str(attrObj)+'.Interval_sevalue',str(outputIntervalAxis_NegZ)+'.firstTerm')
        mc.setAttr(str(outputIntervalAxis_NegZ)+'.secondTerm',6)
        mc.setAttr(str(outputIntervalAxis_NegZ)+'.operation',0)
        mc.setAttr(str(outputIntervalAxis_NegZ)+'.colorIfTrueR',1)
        mc.setAttr(str(outputIntervalAxis_NegZ)+'.colorIfFalseR',0)
        
        ###########################
        ###########################
        ###
        stateY=str(objpre)+'_Y_state_conditon'
        stateZ=str(objpre)+'_Z_state_conditon'
        
        mc.createNode('condition',n=stateZ)
        mc.connectAttr(str(referenceObj)+'.translateY',str(stateZ)+'.firstTerm')
        mc.setAttr(str(stateZ)+'.secondTerm',0)
        mc.setAttr(str(stateZ)+'.operation',3)
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(stateZ)+'.colorIfTrueR')
        mc.setAttr(str(stateZ)+'.colorIfFalseR',0)
        
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(stateZ)+'.colorIfFalseG')
        mc.setAttr(str(stateZ)+'.colorIfTrueG',0)
        
        mc.createNode('condition',n=stateY)
        mc.connectAttr(str(referenceObj)+'.translateZ',str(stateY)+'.firstTerm')
        mc.setAttr(str(stateY)+'.secondTerm',0)
        mc.setAttr(str(stateY)+'.operation',3)
        
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(stateY)+'.colorIfTrueR')
        mc.setAttr(str(stateY)+'.colorIfFalseR',0)
        
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(stateY)+'.colorIfFalseG')
        mc.setAttr(str(stateY)+'.colorIfTrueG',0)
        
        ##########################################################
        ##########################################################
        ##                sdk  interval section 
        frontsdk_pma=str(objpre)+'_front_sdk01_pma'
        upsdk_pma=str(objpre)+'_up_sdk01_pma'
        backsdk_pma=str(objpre)+'_back_sdk01_pma'
        bottomsdk_pma=str(objpre)+'_bottom_sdk01_pma'
        
        mc.createNode('plusMinusAverage',n=frontsdk_pma)
        mc.createNode('plusMinusAverage',n=upsdk_pma)
        mc.createNode('plusMinusAverage',n=backsdk_pma)
        mc.createNode('plusMinusAverage',n=bottomsdk_pma)
        
        frontsdk02_pma=str(objpre)+'_front_sdk02_pma'
        upsdk02_pma=str(objpre)+'_up_sdk02_pma'
        backsdk02_pma=str(objpre)+'_back_sdk02_pma'
        bottomsdk02_pma=str(objpre)+'_bottom_sdk02_pma'
        
        mc.createNode('plusMinusAverage',n=frontsdk02_pma)
        mc.createNode('plusMinusAverage',n=upsdk02_pma)
        mc.createNode('plusMinusAverage',n=backsdk02_pma)
        mc.createNode('plusMinusAverage',n=bottomsdk02_pma)
        
        frontsdk_cdn=str(objpre)+'_front_sdk01_condition'
        upsdk_cdn=str(objpre)+'_up_sdk01_condition'
        backsdk_cdn=str(objpre)+'_back_sdk01_condition'
        bottomsdk_cdn=str(objpre)+'_bottom_sdk01_condition'
        
        mc.createNode('condition',n=frontsdk_cdn)
        mc.createNode('condition',n=upsdk_cdn)
        mc.createNode('condition',n=backsdk_cdn)
        mc.createNode('condition',n=bottomsdk_cdn)
        
        frontsdk_md=str(objpre)+'_front_sdk01_md'
        upsdk_md=str(objpre)+'_up_sdk01_md'
        backsdk_md=str(objpre)+'_back_sdk01_md'
        bottomsdk_md=str(objpre)+'_bottom_sdk01_md'
        
        mc.createNode('multiplyDivide',n=frontsdk_md)
        mc.createNode('multiplyDivide',n=upsdk_md)
        mc.createNode('multiplyDivide',n=backsdk_md)
        mc.createNode('multiplyDivide',n=bottomsdk_md)
        
        frontsdk02_md=str(objpre)+'_front_sdk02_md'
        upsdk02_md=str(objpre)+'_up_sdk02_md'
        backsdk02_md=str(objpre)+'_back_sdk02_md'
        bottomsdk02_md=str(objpre)+'_bottom_sdk02_md'
        
        mc.createNode('multiplyDivide',n=frontsdk02_md)
        mc.createNode('multiplyDivide',n=upsdk02_md)
        mc.createNode('multiplyDivide',n=backsdk02_md)
        mc.createNode('multiplyDivide',n=bottomsdk02_md)
        
        #-------------------------------------------------
        #  str(frontUpsdk_cdn)
        frontUpsdk_cdn=str(objpre)+'_frontUp_sdk01_condition'
        backUpsdk_cdn=str(objpre)+'_backUp_sdk01_condition'
        frontBottomsdk_cdn=str(objpre)+'_frontBottom_sdk01_condition'
        backBottomsdk_cdn=str(objpre)+'_backBottomsdk_sdk01_condition'
        
        mc.createNode('condition',n=frontUpsdk_cdn)
        mc.createNode('condition',n=backUpsdk_cdn)
        mc.createNode('condition',n=frontBottomsdk_cdn)
        mc.createNode('condition',n=backBottomsdk_cdn)
        #
        frontUpsdk_md=str(objpre)+'_frontUp_sdk01_md'
        backUpsdk_md=str(objpre)+'_backUp_sdk01_md'
        frontBottomsdk_md=str(objpre)+'_frontBottom_sdk01_md'
        backBottomsdk_md=str(objpre)+'_backBottomsdk_sdk01_md'
        
        mc.createNode('multiplyDivide',n=frontUpsdk_md)
        mc.createNode('multiplyDivide',n=backUpsdk_md)
        mc.createNode('multiplyDivide',n=frontBottomsdk_md)
        mc.createNode('multiplyDivide',n=backBottomsdk_md)
        #
        frontUpsdk02_md=str(objpre)+'_frontUp_sdk02_md'
        backUpsdk02_md=str(objpre)+'_backUp_sdk02_md'
        frontBottomsdk02_md=str(objpre)+'_frontBottom_sdk02_md'
        backBottomsdk02_md=str(objpre)+'_backBottomsdk_sdk02_md'
        
        mc.createNode('multiplyDivide',n=frontUpsdk02_md)
        mc.createNode('multiplyDivide',n=backUpsdk02_md)
        mc.createNode('multiplyDivide',n=frontBottomsdk02_md)
        mc.createNode('multiplyDivide',n=backBottomsdk02_md)

        
        #
        #-------------------------------------------------
        
        
        ###################################   front
        mc.connectAttr(str(outputInterval01)+'.outColorR',str(frontsdk_pma)+'.input1D[0]')
        mc.connectAttr(str(outputInterval03)+'.outColorR',str(frontsdk_pma)+'.input1D[1]')
        mc.connectAttr(str(outputIntervalAxis_PosZ)+'.outColorR',str(frontsdk_pma)+'.input1D[2]')
        mc.connectAttr(str(frontsdk_pma)+'.output1D',str(frontsdk_cdn)+'.firstTerm')
        mc.setAttr(str(frontsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(frontsdk_cdn)+'.operation',0)
        mc.setAttr(str(frontsdk_cdn)+'.colorIfFalseR',0)
        
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontsdk02_pma)+'.input2D[1].input2Dx')
        mc.setAttr(str(frontsdk02_pma)+'.input2D[0].input2Dx',90)
        mc.setAttr(str(frontsdk02_pma)+'.operation',2)
        
        mc.connectAttr(str(frontsdk02_pma)+'.output2D.output2Dx',str(frontsdk_md)+'.input1.input1X')
        mc.setAttr(str(frontsdk_md)+'.input2.input2X',90)
        mc.setAttr(str(frontsdk_md)+'.operation',2)
        mc.connectAttr(str(frontsdk_md)+'.outputX',str(frontsdk_cdn)+'.colorIfTrueR')
        
        mc.connectAttr(str(frontsdk_cdn)+'.outColorR',str(frontsdk02_md)+'.input1.input1X')
        mc.connectAttr(str(stateY)+'.outColorR',str(frontsdk02_md)+'.input2.input2X')
        
        mc.connectAttr(str(frontsdk02_md)+'.output.outputX',str(attrObj)+'.front_driver')
        ###################################   up
        mc.connectAttr(str(outputInterval01)+'.outColorR',str(upsdk_pma)+'.input1D[0]')
        mc.connectAttr(str(outputInterval02)+'.outColorR',str(upsdk_pma)+'.input1D[1]')
        mc.connectAttr(str(outputIntervalAxis_PosY)+'.outColorR',str(upsdk_pma)+'.input1D[2]')
        mc.connectAttr(str(upsdk_pma)+'.output1D',str(upsdk_cdn)+'.firstTerm')
        mc.setAttr(str(upsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(upsdk_cdn)+'.operation',0)
        mc.setAttr(str(upsdk_cdn)+'.colorIfFalseR',0)
        
        upanglesdk_cdn=str(objpre)+'_front_anglesdk_condition'
        mc.createNode('condition',n=upanglesdk_cdn)
        mc.connectAttr(str(attrObj)+'.angle_base',str(upanglesdk_cdn)+'.firstTerm')
        mc.setAttr(str(upanglesdk_cdn)+'.secondTerm',90)
        mc.setAttr(str(upanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(upsdk02_pma)+'.input2D[1].input2Dx')
        mc.setAttr(str(upsdk02_pma)+'.input2D[0].input2Dx',180)
        mc.setAttr(str(upsdk02_pma)+'.operation',2)
        mc.connectAttr(str(upsdk02_pma)+'.output2D.output2Dx',str(upanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(attrObj)+'.angle_base',str(upanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(upanglesdk_cdn)+'.outColorR',str(upsdk_md)+'.input1.input1X')
        mc.setAttr(str(upsdk_md)+'.input2.input2X',90)
        mc.setAttr(str(upsdk_md)+'.operation',2)
        mc.connectAttr(str(upsdk_md)+'.outputX',str(upsdk_cdn)+'.colorIfTrueR')
        
        mc.connectAttr(str(upsdk_cdn)+'.outColorR',str(upsdk02_md)+'.input1.input1X')
        mc.connectAttr(str(stateZ)+'.outColorR',str(upsdk02_md)+'.input2.input2X')
        
        mc.connectAttr(str(upsdk02_md)+'.output.outputX',str(attrObj)+'.up_driver')
        ###################################  back
        mc.connectAttr(str(outputInterval02)+'.outColorR',str(backsdk_pma)+'.input1D[0]')
        mc.connectAttr(str(outputInterval04)+'.outColorR',str(backsdk_pma)+'.input1D[1]')
        mc.connectAttr(str(outputIntervalAxis_NegZ)+'.outColorR',str(backsdk_pma)+'.input1D[2]')
        mc.connectAttr(str(backsdk_pma)+'.output1D',str(backsdk_cdn)+'.firstTerm')
        mc.setAttr(str(backsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(backsdk_cdn)+'.operation',0)
        mc.setAttr(str(backsdk_cdn)+'.colorIfFalseR',0)
        
        mc.connectAttr(str(attrObj)+'.angle_base',str(backsdk02_pma)+'.input2D[0].input2Dx')
        mc.setAttr(str(backsdk02_pma)+'.input2D[1].input2Dx',90)
        mc.setAttr(str(backsdk02_pma)+'.operation',2)
        
        mc.connectAttr(str(backsdk02_pma)+'.output2D.output2Dx',str(backsdk_md)+'.input1.input1X')
        mc.setAttr(str(backsdk_md)+'.input2.input2X',90)
        mc.setAttr(str(backsdk_md)+'.operation',2)
        mc.connectAttr(str(backsdk_md)+'.outputX',str(backsdk_cdn)+'.colorIfTrueR')
        
        mc.connectAttr(str(backsdk_cdn)+'.outColorR',str(backsdk02_md)+'.input1.input1X')
        mc.connectAttr(str(stateY)+'.outColorG',str(backsdk02_md)+'.input2.input2X')
        
        mc.connectAttr(str(backsdk02_md)+'.output.outputX',str(attrObj)+'.back_driver')
        
        ###################################   bottom
        mc.connectAttr(str(outputInterval03)+'.outColorR',str(bottomsdk_pma)+'.input1D[0]')
        mc.connectAttr(str(outputInterval04)+'.outColorR',str(bottomsdk_pma)+'.input1D[1]')
        mc.connectAttr(str(outputIntervalAxis_NegY)+'.outColorR',str(bottomsdk_pma)+'.input1D[2]')
        mc.connectAttr(str(bottomsdk_pma)+'.output1D',str(bottomsdk_cdn)+'.firstTerm')
        mc.setAttr(str(bottomsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(bottomsdk_cdn)+'.operation',0)
        mc.setAttr(str(bottomsdk_cdn)+'.colorIfFalseR',0)
        
        bottomanglesdk_cdn=str(objpre)+'_bottom_anglesdk_condition'
        mc.createNode('condition',n=bottomanglesdk_cdn)
        mc.connectAttr(str(attrObj)+'.angle_base',str(bottomanglesdk_cdn)+'.firstTerm')
        mc.setAttr(str(bottomanglesdk_cdn)+'.secondTerm',90)
        mc.setAttr(str(bottomanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(bottomsdk02_pma)+'.input2D[1].input2Dx')
        mc.setAttr(str(bottomsdk02_pma)+'.input2D[0].input2Dx',180)
        mc.setAttr(str(bottomsdk02_pma)+'.operation',2)
        mc.connectAttr(str(bottomsdk02_pma)+'.output2D.output2Dx',str(bottomanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(attrObj)+'.angle_base',str(bottomanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(bottomanglesdk_cdn)+'.outColorR',str(bottomsdk_md)+'.input1.input1X')
        mc.setAttr(str(bottomsdk_md)+'.input2.input2X',90)
        mc.setAttr(str(bottomsdk_md)+'.operation',2)
        mc.connectAttr(str(bottomsdk_md)+'.outputX',str(bottomsdk_cdn)+'.colorIfTrueR')
        
        mc.connectAttr(str(bottomsdk_cdn)+'.outColorR',str(bottomsdk02_md)+'.input1.input1X')
        mc.connectAttr(str(stateZ)+'.outColorG',str(bottomsdk02_md)+'.input2.input2X')
        
        mc.connectAttr(str(bottomsdk02_md)+'.output.outputX',str(attrObj)+'.bottom_driver')
        
        #######################################################################
        #####---------------------------------------------------
        #
        ##############################   frontUP_driver 
        mc.connectAttr(str(outputInterval01)+'.outColorR',str(frontUpsdk_cdn)+'.firstTerm')
        mc.setAttr(str(frontUpsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(frontUpsdk_cdn)+'.operation',0)
        mc.setAttr(str(frontUpsdk_cdn)+'.colorIfFalseR',0)
        mc.setAttr(str(frontUpsdk_cdn)+'.colorIfTrueR',1)
        
        frontUpanglesdk_cdn=str(objpre)+'_frontUp_anglesdk_condition'
        mc.createNode('condition',n=frontUpanglesdk_cdn)
        
        frontUpsdk02_pma=str(objpre)+'_frontUp_anglesdk_pma'
        mc.createNode('plusMinusAverage',n=frontUpsdk02_pma)

        
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontUpanglesdk_cdn)+'.firstTerm')
        mc.connectAttr(str(attrObj)+'.angle_frontUp',str(frontUpanglesdk_cdn)+'.secondTerm')
        mc.setAttr(str(frontUpanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontUpsdk02_pma)+'.input3D[1].input3Dx')
        mc.setAttr(str(frontUpsdk02_pma)+'.input3D[0].input3Dx',90)
        #mc.connectAttr(str(attrObj)+'.angle_base',str(frontUpsdk02_pma)+'.input3D[1].input3Dy')
        #mc.connectAttr(str(attrObj)+'.angle_frontUp',str(frontUpsdk02_pma)+'.input3D[0].input3Dy')
        
        mc.connectAttr(str(attrObj)+'.angle_frontUp',str(frontUpsdk02_pma)+'.input3D[1].input3Dz')
        mc.setAttr(str(frontUpsdk02_pma)+'.input3D[0].input3Dz',90)
        mc.setAttr(str(frontUpsdk02_pma)+'.operation',2)
        
        
        mc.connectAttr(str(frontUpsdk02_pma)+'.output3D.output3Dx',str(frontUpanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontUpanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(frontUpsdk02_pma)+'.output3D.output3Dz',str(frontUpanglesdk_cdn)+'.colorIfTrueG')
        mc.connectAttr(str(attrObj)+'.angle_frontUp',str(frontUpanglesdk_cdn)+'.colorIfFalseG')

        
        mc.connectAttr(str(frontUpanglesdk_cdn)+'.outColorR',str(frontUpsdk_md)+'.input1.input1X')
        mc.connectAttr(str(frontUpanglesdk_cdn)+'.outColorG',str(frontUpsdk_md)+'.input2.input2X')
        mc.setAttr(str(frontUpsdk_md)+'.operation',2)
        
        frontUpsdkout_md=str(objpre)+'_frontUp_anglesdkout_md'
        mc.createNode('multiplyDivide',n=frontUpsdkout_md)
        
        mc.connectAttr(str(frontUpsdk_md)+'.outputX',str(frontUpsdkout_md)+'.input1.input1X')
        mc.connectAttr(str(frontUpsdk_cdn)+'.outColorR',str(frontUpsdkout_md)+'.input2.input2X')

        mc.setAttr(str(frontUpsdkout_md)+'.operation',1)
        
        mc.connectAttr(str(frontUpsdkout_md)+'.outputX',str(frontUpsdk02_md)+'.input2.input2X')
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(frontUpsdk02_md)+'.input1.input1X')
        mc.setAttr(str(frontUpsdk02_md)+'.operation',1)
        mc.connectAttr(str(frontUpsdk02_md)+'.output.outputX',str(attrObj)+'.frontUp_driver')
        
        ##############################   backUP_driver 
        mc.connectAttr(str(outputInterval02)+'.outColorR',str(backUpsdk_cdn)+'.firstTerm')
        mc.setAttr(str(backUpsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(backUpsdk_cdn)+'.operation',0)
        mc.setAttr(str(backUpsdk_cdn)+'.colorIfFalseR',0)
        mc.setAttr(str(backUpsdk_cdn)+'.colorIfTrueR',1)
        
        backUpanglesdk_cdn=str(objpre)+'_backUp_anglesdk_condition'
        mc.createNode('condition',n=backUpanglesdk_cdn)
        
        backUpsdk02_pma=str(objpre)+'_backUp_anglesdk_pma'
        mc.createNode('plusMinusAverage',n=backUpsdk02_pma)


        
        mc.connectAttr(str(attrObj)+'.angle_base',str(backUpanglesdk_cdn)+'.firstTerm')
        mc.connectAttr(str(attrObj)+'.angle_backUp',str(backUpanglesdk_cdn)+'.secondTerm')
        mc.setAttr(str(backUpanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(backUpsdk02_pma)+'.input3D[1].input3Dx')
        mc.setAttr(str(backUpsdk02_pma)+'.input3D[0].input3Dx',180)
        mc.connectAttr(str(attrObj)+'.angle_base',str(backUpsdk02_pma)+'.input3D[0].input3Dy')
        mc.setAttr(str(backUpsdk02_pma)+'.input3D[1].input3Dy',90)
        
        
        mc.connectAttr(str(attrObj)+'.angle_backUp',str(backUpsdk02_pma)+'.input2D[0].input2Dx')
        mc.setAttr(str(backUpsdk02_pma)+'.input2D[1].input2Dx',90)

        mc.connectAttr(str(attrObj)+'.angle_backUp',str(backUpsdk02_pma)+'.input3D[1].input3Dz')
        mc.setAttr(str(backUpsdk02_pma)+'.input3D[0].input3Dz',180)
        mc.setAttr(str(backUpsdk02_pma)+'.operation',2)
        
        
        mc.connectAttr(str(backUpsdk02_pma)+'.output3D.output3Dx',str(backUpanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(backUpsdk02_pma)+'.output3D.output3Dy',str(backUpanglesdk_cdn)+'.colorIfFalseR')
        #mc.connectAttr(str(attrObj)+'.angle_base',str(backUpanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(backUpsdk02_pma)+'.output3D.output3Dz',str(backUpanglesdk_cdn)+'.colorIfTrueG')
        mc.connectAttr(str(backUpsdk02_pma)+'.output2D.output2Dx',str(backUpanglesdk_cdn)+'.colorIfFalseG')

        
        mc.connectAttr(str(backUpanglesdk_cdn)+'.outColorR',str(backUpsdk_md)+'.input1.input1X')
        mc.connectAttr(str(backUpanglesdk_cdn)+'.outColorG',str(backUpsdk_md)+'.input2.input2X')
        mc.setAttr(str(backUpsdk_md)+'.operation',2)
        
        backUpsdkout_md=str(objpre)+'_backUp_anglesdkout_md'
        mc.createNode('multiplyDivide',n=backUpsdkout_md)
        
        mc.connectAttr(str(backUpsdk_md)+'.outputX',str(backUpsdkout_md)+'.input1.input1X')
        mc.connectAttr(str(backUpsdk_cdn)+'.outColorR',str(backUpsdkout_md)+'.input2.input2X')

        mc.setAttr(str(backUpsdkout_md)+'.operation',1)
        
        mc.connectAttr(str(backUpsdkout_md)+'.outputX',str(backUpsdk02_md)+'.input2.input2X')
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(backUpsdk02_md)+'.input1.input1X')
        mc.setAttr(str(backUpsdk02_md)+'.operation',1)
        mc.connectAttr(str(backUpsdk02_md)+'.output.outputX',str(attrObj)+'.backUp_driver')
        
        ##############################   frontBottom_driver 
        mc.connectAttr(str(outputInterval03)+'.outColorR',str(frontBottomsdk_cdn)+'.firstTerm')
        mc.setAttr(str(frontBottomsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(frontBottomsdk_cdn)+'.operation',0)
        mc.setAttr(str(frontBottomsdk_cdn)+'.colorIfFalseR',0)
        mc.setAttr(str(frontBottomsdk_cdn)+'.colorIfTrueR',1)
        
        frontBottomanglesdk_cdn=str(objpre)+'_frontBottom_anglesdk_condition'
        mc.createNode('condition',n=frontBottomanglesdk_cdn)
        
        frontBottomsdk02_pma=str(objpre)+'_frontBottom_anglesdk_pma'
        mc.createNode('plusMinusAverage',n=frontBottomsdk02_pma)

        
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontBottomanglesdk_cdn)+'.firstTerm')
        mc.connectAttr(str(attrObj)+'.angle_frontBottom',str(frontBottomanglesdk_cdn)+'.secondTerm')
        mc.setAttr(str(frontBottomanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontBottomsdk02_pma)+'.input3D[1].input3Dx')
        mc.setAttr(str(frontBottomsdk02_pma)+'.input3D[0].input3Dx',90)
        #mc.connectAttr(str(attrObj)+'.angle_base',str(frontBottomsdk02_pma)+'.input3D[1].input3Dy')
        #mc.connectAttr(str(attrObj)+'.angle_frontBottom',str(frontBottomsdk02_pma)+'.input3D[0].input3Dy')
        
        mc.connectAttr(str(attrObj)+'.angle_frontBottom',str(frontBottomsdk02_pma)+'.input3D[1].input3Dz')
        mc.setAttr(str(frontBottomsdk02_pma)+'.input3D[0].input3Dz',90)
        mc.setAttr(str(frontBottomsdk02_pma)+'.operation',2)
        
        
        mc.connectAttr(str(frontBottomsdk02_pma)+'.output3D.output3Dx',str(frontBottomanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(attrObj)+'.angle_base',str(frontBottomanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(frontBottomsdk02_pma)+'.output3D.output3Dz',str(frontBottomanglesdk_cdn)+'.colorIfTrueG')
        mc.connectAttr(str(attrObj)+'.angle_frontBottom',str(frontBottomanglesdk_cdn)+'.colorIfFalseG')

        
        mc.connectAttr(str(frontBottomanglesdk_cdn)+'.outColorR',str(frontBottomsdk_md)+'.input1.input1X')
        mc.connectAttr(str(frontBottomanglesdk_cdn)+'.outColorG',str(frontBottomsdk_md)+'.input2.input2X')
        mc.setAttr(str(frontBottomsdk_md)+'.operation',2)
        
        frontBottomsdkout_md=str(objpre)+'_frontBottom_anglesdkout_md'
        mc.createNode('multiplyDivide',n=frontBottomsdkout_md)
        
        mc.connectAttr(str(frontBottomsdk_md)+'.outputX',str(frontBottomsdkout_md)+'.input1.input1X')
        mc.connectAttr(str(frontBottomsdk_cdn)+'.outColorR',str(frontBottomsdkout_md)+'.input2.input2X')

        mc.setAttr(str(frontBottomsdkout_md)+'.operation',1)
        
        mc.connectAttr(str(frontBottomsdkout_md)+'.outputX',str(frontBottomsdk02_md)+'.input2.input2X')
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(frontBottomsdk02_md)+'.input1.input1X')
        mc.setAttr(str(frontBottomsdk02_md)+'.operation',1)
        mc.connectAttr(str(frontBottomsdk02_md)+'.output.outputX',str(attrObj)+'.frontBottom_driver')
        
        ##############################   backBottom_driver 
        mc.connectAttr(str(outputInterval04)+'.outColorR',str(backBottomsdk_cdn)+'.firstTerm')
        mc.setAttr(str(backBottomsdk_cdn)+'.secondTerm',1)
        mc.setAttr(str(backBottomsdk_cdn)+'.operation',0)
        mc.setAttr(str(backBottomsdk_cdn)+'.colorIfFalseR',0)
        mc.setAttr(str(backBottomsdk_cdn)+'.colorIfTrueR',1)
        
        backBottomanglesdk_cdn=str(objpre)+'_backBottom_anglesdk_condition'
        mc.createNode('condition',n=backBottomanglesdk_cdn)
        
        backBottomsdk02_pma=str(objpre)+'_backBottom_anglesdk_pma'
        mc.createNode('plusMinusAverage',n=backBottomsdk02_pma)

        
        mc.connectAttr(str(attrObj)+'.angle_base',str(backBottomanglesdk_cdn)+'.firstTerm')
        mc.connectAttr(str(attrObj)+'.angle_backBottom',str(backBottomanglesdk_cdn)+'.secondTerm')
        mc.setAttr(str(backBottomanglesdk_cdn)+'.operation',2)
        mc.connectAttr(str(attrObj)+'.angle_base',str(backBottomsdk02_pma)+'.input3D[1].input3Dx')
        mc.setAttr(str(backBottomsdk02_pma)+'.input3D[0].input3Dx',180)
        

        mc.connectAttr(str(attrObj)+'.angle_base',str(backBottomsdk02_pma)+'.input3D[0].input3Dy')
        mc.setAttr(str(backBottomsdk02_pma)+'.input3D[1].input3Dy',90)
        
        mc.connectAttr(str(attrObj)+'.angle_backBottom',str(backBottomsdk02_pma)+'.input3D[1].input3Dz')
        mc.setAttr(str(backBottomsdk02_pma)+'.input3D[0].input3Dz',180)
        
        mc.connectAttr(str(attrObj)+'.angle_backBottom',str(backBottomsdk02_pma)+'.input2D[0].input2Dx')
        mc.setAttr(str(backBottomsdk02_pma)+'.input2D[1].input2Dx',90)
        
        mc.setAttr(str(backBottomsdk02_pma)+'.operation',2)
        
        
        mc.connectAttr(str(backBottomsdk02_pma)+'.output3D.output3Dx',str(backBottomanglesdk_cdn)+'.colorIfTrueR')
        mc.connectAttr(str(backBottomsdk02_pma)+'.output3D.output3Dy',str(backBottomanglesdk_cdn)+'.colorIfFalseR')
        #mc.connectAttr(str(attrObj)+'.angle_base',str(backBottomanglesdk_cdn)+'.colorIfFalseR')
        
        mc.connectAttr(str(backBottomsdk02_pma)+'.output3D.output3Dz',str(backBottomanglesdk_cdn)+'.colorIfTrueG')
        mc.connectAttr(str(backBottomsdk02_pma)+'.output2D.output2Dx',str(backBottomanglesdk_cdn)+'.colorIfFalseG')

        
        mc.connectAttr(str(backBottomanglesdk_cdn)+'.outColorR',str(backBottomsdk_md)+'.input1.input1X')
        mc.connectAttr(str(backBottomanglesdk_cdn)+'.outColorG',str(backBottomsdk_md)+'.input2.input2X')
        mc.setAttr(str(backBottomsdk_md)+'.operation',2)
        
        backBottomsdkout_md=str(objpre)+'_backBottom_anglesdkout_md'
        mc.createNode('multiplyDivide',n=backBottomsdkout_md)
        
        mc.connectAttr(str(backBottomsdk_md)+'.outputX',str(backBottomsdkout_md)+'.input1.input1X')
        mc.connectAttr(str(backBottomsdk_cdn)+'.outColorR',str(backBottomsdkout_md)+'.input2.input2X')

        mc.setAttr(str(backBottomsdkout_md)+'.operation',1)
        
        mc.connectAttr(str(backBottomsdkout_md)+'.outputX',str(backBottomsdk02_md)+'.input2.input2X')
        mc.connectAttr(str(objpre)+'_bridge'+'.driver_vulue',str(backBottomsdk02_md)+'.input1.input1X')
        mc.setAttr(str(backBottomsdk02_md)+'.operation',1)
        mc.connectAttr(str(backBottomsdk02_md)+'.output.outputX',str(attrObj)+'.backBottom_driver')
        
        
        
        
        

        
        